import axios from 'axios'



// create an axios instance
const service = axios.create({
  baseURL: "http://localhost:8888/mall", // url = base url + request url
  timeout: 5000 // request timeout
})

// 请求拦截器
service.interceptors.request.use(
  config => {
    console.log("请求拦截器",config)
    // token
    config.headers['mailToken'] =localStorage.getItem("mailToken")

    return config
  },
  error => {
    // do something with request error
    console.log(error) // for debug
    return Promise.reject(error)
  }
)
// =============================================================================

// 响应拦截器
service.interceptors.response.use(

  response => {
    
  console.log("响应拦截器：",response)
    const res = response.data

    //成功
    if(res.code == 20000){

    
    }
   
    //失败
   if(res.code ==40000){
     
    }
      return res
 
  },
  error => {
    console.log('err' + error) // for debug
 
    return Promise.reject(error)
  }
)

export default service
